﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace TCPServiceWithWindowsService
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in both code and config file together.
    public class KalficomService : IService1
    {
        /*
   * Ibraheem Osama Mohamed
   * @IbraheemOsamaMo
   */
        //string ConnectionString = string.Format("metadata=res://*/Model2.csdl|res://*/Model2.ssdl|res://*/Model2.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source={0};initial catalog={1};user id=kalficom;password=k@lf!c0m;MultipleActiveResultSets=True;App=EntityFramework&quot;", "localhost", "kalfi_paster");

        public bool InsertEmployee(EmployeeTCP employee)
        {
            FactoryEntities context = new FactoryEntities();

            Employee newEmp = new Employee();
            newEmp.Name = employee.name;
            newEmp.Postion = employee.postion;
            context.Employees.Add(newEmp);
            context.SaveChanges();
            return true;
        }

        public EmployeeTCP GetEmployeeWithID(string name)
        {
            FactoryEntities context = new FactoryEntities();

            var empWithName = (from x in context.Employees
                               where x.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase)
                               select x).FirstOrDefault();
            EmployeeTCP eTCP = new EmployeeTCP();
            eTCP.name = empWithName.Name;
            eTCP.postion = empWithName.Postion;
            return eTCP;

        }

        public List<EmployeeTCP> GetAllEmployee()
        {
            var list = new List<EmployeeTCP>();
            FactoryEntities context = new FactoryEntities();
            foreach (var emp in context.Employees.ToList())
            {
                EmployeeTCP eTCP = new EmployeeTCP();
                eTCP.name = emp.Name;
                eTCP.postion = emp.Postion;
                list.Add(eTCP);
            }
            return list;
        }

        public List<ZoneTCP> GetAllZone()
        {
            var list = new List<ZoneTCP>();
            kalficomEntities context = new kalficomEntities();
            foreach (var zone in context.k_zone_geographic.ToList())
            {
                ZoneTCP kZone = new ZoneTCP();
                kZone.id = zone.zone_id;
                kZone.code = zone.zone_code;
                kZone.label = zone.zone_label;
                list.Add(kZone);
            }
            return list;
        }

        public List<UserTCP> GetAllUser()
        {
            var list = new List<UserTCP>();
            kalficomEntities context = new kalficomEntities();
            //context.Database.Connection.ConnectionString = ConnectionString;
            foreach (var User in context.k_user.ToList())
            {
                UserTCP kUser = new UserTCP();
                kUser.id = User.user_id;
                kUser.login = User.user_login;
                kUser.pwd = User.user_pwd;
                kUser.isadmin = User.user_is_admin;
                kUser.istablet = User.user_is_tablet;
                kUser.iscontract = User.user_can_create_contract;
                kUser.iscalypso = User.user_can_update_calypso;
                kUser.fname = User.user_first_name;
                kUser.lname = User.user_last_name;
                kUser.mail = User.user_mail;
                kUser.phone = User.user_phone;
                kUser.usercreate = User.user_create;
                kUser.datecreate = User.date_create;
                list.Add(kUser);
            }
            return list;
        }

        public List<ClientTakenTCP> GetAllClientTaken()
        {
            var list = new List<ClientTakenTCP>();
            kalficomEntities context = new kalficomEntities();
            foreach (var kclient in context.k_client_taken.ToList())
            {
                ClientTakenTCP client = new ClientTakenTCP();
                client.client_taken_id = kclient.client_taken_id;
                client.client_taken_code = kclient.client_taken_code;
                client.zone_id = kclient.zone_id;
                client.cont_id = kclient.cont_id;
                client.user_create = kclient.user_create;
                client.date_create = kclient.date_create;
                list.Add(client);
            }
            return list;
        }

        public List<NTIERS_XTCP> GetAllNTIERS_X()
        {
            var list = new List<NTIERS_XTCP>();
            kalficomEntities context = new kalficomEntities();
            foreach (var kNTIERS in context.NTIERS_X.ToList())
            {
                NTIERS_XTCP NTIERS = new NTIERS_XTCP();
                NTIERS.TX_CODE = kNTIERS.TX_CODE;
                NTIERS.TX_SECT = kNTIERS.TX_SECT;
                NTIERS.TX_REGION = kNTIERS.TX_REGION;
                NTIERS.TX_PAYS = kNTIERS.TX_PAYS;
                NTIERS.TX_DEPT = kNTIERS.TX_DEPT;
                  NTIERS.TX_GROUPE = kNTIERS.TX_GROUPE;
                  NTIERS.TX_TYPE = kNTIERS.TX_TYPE;
                  NTIERS.TX_NOM = kNTIERS.TX_NOM;
                  NTIERS.TX_PRENOM = kNTIERS.TX_PRENOM;
                  NTIERS.TX_TITRE = kNTIERS.TX_TITRE;
                  NTIERS.TX_VETO = kNTIERS.TX_VETO;
                  NTIERS.TX_ADR1 = kNTIERS.TX_ADR1;
                  NTIERS.TX_ADR2 = kNTIERS.TX_ADR2;
                  NTIERS.TX_ADR3 = kNTIERS.TX_ADR3;
                  NTIERS.TX_INSEE = kNTIERS.TX_INSEE;
                  NTIERS.TX_VILLE = kNTIERS.TX_VILLE;
                  NTIERS.TX_CP = kNTIERS.TX_CP;
                  NTIERS.TX_TEL = kNTIERS.TX_TEL;
                  NTIERS.TX_FAX = kNTIERS.TX_FAX;
                  NTIERS.TX_DATREF = kNTIERS.TX_DATREF;
                  NTIERS.TX_NUM = kNTIERS.TX_NUM;
                  NTIERS.TX_CHEP = kNTIERS.TX_CHEP;
                  NTIERS.TX_COM = kNTIERS.TX_COM;
                  NTIERS.TX_MINI = kNTIERS.TX_MINI;
                  NTIERS.TX_BUL = kNTIERS.TX_BUL;
                  NTIERS.TX_NBUL = kNTIERS.TX_NBUL;
                  NTIERS.TX_RES = kNTIERS.TX_RES;
                  NTIERS.TX_FAC = kNTIERS.TX_FAC;
                  NTIERS.TX_CODPAI = kNTIERS.TX_CODPAI;
                  NTIERS.TX_EMAIL = kNTIERS.TX_EMAIL;
                  NTIERS.TX_MAILACT = kNTIERS.TX_MAILACT;
                  NTIERS.TX_MESSAGE = kNTIERS.TX_MESSAGE;
                  NTIERS.TX_MOBILE = kNTIERS.TX_MOBILE;
                  NTIERS.TX_MPSC = kNTIERS.TX_MPSC;
                  NTIERS.TX_BP = kNTIERS.TX_BP;
                  NTIERS.TX_NTVA = kNTIERS.TX_NTVA;
                  NTIERS.TX_SIRET = kNTIERS.TX_SIRET;
                  NTIERS.TX_LATITUD = kNTIERS.TX_LATITUD;
                  NTIERS.TX_LONGITU = kNTIERS.TX_LONGITU;
                  NTIERS.TX_ZONE = kNTIERS.TX_ZONE;
                  NTIERS.TX_PERACT = kNTIERS.TX_PERACT;
                  NTIERS.TX_ANAACT = kNTIERS.TX_ANAACT;
                  NTIERS.TX_DUREE = kNTIERS.TX_DUREE;
                  NTIERS.TX_SSTRAIT = kNTIERS.TX_SSTRAIT;
                  NTIERS.TX_LANGUE = kNTIERS.TX_LANGUE;
                  NTIERS.TX_SANDRE = kNTIERS.TX_SANDRE;
                  NTIERS.TX_COMTOUR = kNTIERS.TX_COMTOUR;
                  NTIERS.TX_EDITSEL = kNTIERS.TX_EDITSEL;
                  NTIERS.TX_ATEL = kNTIERS.TX_ATEL;
                  NTIERS.TX_CODPRES = kNTIERS.TX_CODPRES;
                  NTIERS.TX_CODVET = kNTIERS.TX_CODVET;
                  NTIERS.TX_PRES = kNTIERS.TX_PRES;
                  NTIERS.TX_VGC = kNTIERS.TX_VGC;
                  list.Add(NTIERS);
            }
            return list;
        }

        public List<TakenTCP> GetAllTaken()
        {
            var list = new List<TakenTCP>();
            kalficomEntities context = new kalficomEntities();
            foreach (var ktaken in context.k_taken.ToList())
            {
                TakenTCP taken = new TakenTCP();
                taken.taken_id = ktaken.taken_id;
                taken.prod_code = ktaken.prod_code;
                taken.taken_type = ktaken.taken_type;
                taken.taken_code = ktaken.taken_code;
                taken.client_taken_id = ktaken.client_taken_id;
                taken.surv_code = ktaken.surv_code;
                taken.taken_point_code = ktaken.taken_point_code;
                taken.taken_point_label = ktaken.taken_point_label;
                taken.taken_point_modifiable = ktaken.taken_point_modifiable;
                taken.taken_date = ktaken.taken_date;
                taken.days_taken = ktaken.days_taken;
                taken.months_taken = ktaken.months_taken;
                taken.years_taken = ktaken.years_taken;
                taken.taken_comment = ktaken.taken_comment;
                taken.taken_point_day = ktaken.taken_point_day;
                taken.taken_date_next = ktaken.taken_date_next;
                taken.taken_date_last = ktaken.taken_date_last;
                taken.amount = ktaken.amount;
                taken.user_create = ktaken.user_create;
                taken.date_create = ktaken.date_create;
                list.Add(taken);
            }
            return list;
        }

        public List<ContractTCP> GetAllContract()
        {
            var list = new List<ContractTCP>();
            kalficomEntities context = new kalficomEntities();
            foreach (var kcontract in context.k_contract.ToList())
            {
                ContractTCP contract = new ContractTCP();
                contract.cont_id = kcontract.cont_id;
                contract.cont_number = kcontract.cont_number;
                contract.date_start = kcontract.date_start;
                contract.date_end = kcontract.date_end;
                contract.client_to_invoice = kcontract.client_to_invoice;
                contract.active = kcontract.active;
                contract.user_create = kcontract.user_create;
                contract.date_create = kcontract.date_create;
                list.Add(contract);
            }
            return list;
        }

        public List<SystemParameterTCP> GetAllSystemParameter()
        {
            var list = new List<SystemParameterTCP>();
            kalficomEntities context = new kalficomEntities();
            foreach (var ksystemparameter in context.k_system_parameter.ToList())
            {
                SystemParameterTCP systemparameter = new SystemParameterTCP();
                systemparameter.sp_id = ksystemparameter.sp_id;
                systemparameter.sp_patch = ksystemparameter.sp_patch;
                list.Add(systemparameter);
            }
            return list;
        }

        public List<TakenAnalyzeTCP> GetAllTakenAnalyze()
        {
            var list = new List<TakenAnalyzeTCP>();
            kalficomEntities context = new kalficomEntities();
            foreach (var ktakenanalyze in context.k_taken_analyze.ToList())
            {
                TakenAnalyzeTCP takenanalyze = new TakenAnalyzeTCP();
                takenanalyze.analyze_code = ktakenanalyze.analyze_code;
                takenanalyze.analyze_label = ktakenanalyze.analyze_label;
                takenanalyze.taken_id = ktakenanalyze.taken_id;
                takenanalyze.to_do = ktakenanalyze.to_do;
                takenanalyze.user_create = ktakenanalyze.user_create;
                takenanalyze.date_create = ktakenanalyze.date_create;
                list.Add(takenanalyze);
            }
            return list;
        }

        public List<NproduitTCP> GetAllNproduit()
        {
            var list = new List<NproduitTCP>();
            kalficomEntities context = new kalficomEntities();
            foreach (var p in context.NPRODUIT.ToList())
            {
                NproduitTCP prod = new NproduitTCP();
                prod.PRD_CODE = p.PRD_CODE;
                prod.PRD_LIB = p.PRD_LIB;
                prod.PRD_LIBID1 = p.PRD_LIBID1;
                prod.PRD_LIBID2 = p.PRD_LIBID2;
                prod.PRD_LIBID3 = p.PRD_LIBID3;
                prod.PRD_LIBID4 = p.PRD_LIBID4;
                prod.PRD_LIBID5 = p.PRD_LIBID5;
                prod.PRD_LIBID6 = p.PRD_LIBID6;
                prod.PRD_LIBID7 = p.PRD_LIBID7;
                prod.PRD_LIBID8 = p.PRD_LIBID8;
                prod.PRD_LIBID9 = p.PRD_LIBID9;
                prod.PRD_LIBID10 = p.PRD_LIBID10;
                prod.PRD_LIBID11 = p.PRD_LIBID11;
                prod.PRD_LIBID12 = p.PRD_LIBID12;
                prod.PRD_OBLID = p.PRD_OBLID;
                prod.PRD_TABL = p.PRD_TABL;
                prod.PRD_TYPID = p.PRD_TYPID;
                list.Add(prod);
            }
            return list;
        }

        public List<SecteurTCP> GetAllSecteur()
        {
            var list = new List<SecteurTCP>();
            kalficomEntities context = new kalficomEntities();
            foreach (var s in context.SECTEURS.ToList())
            {
                SecteurTCP sec = new SecteurTCP();
                sec.SE_CODE = s.SE_CODE;
                sec.SE_LIBELLE = s.SE_LIBELLE;
                list.Add(sec);
            }
            return list;
        }

        public List<PlanContTCP> GetAllPlanCont()
        {
            var list = new List<PlanContTCP>();
            kalficomEntities context = new kalficomEntities();
            foreach (var p in context.PLANCONT.ToList())
            {
                PlanContTCP planCont = new PlanContTCP();
                planCont.PC_CODE = p.PC_CODE;
                planCont.PC_LIBELLE = p.PC_LIBELLE;
                list.Add(planCont);
            }
            return list;
        }

        public List<AnaPlanTCP> GetAllAnaPlan()
        {
            var list = new List<AnaPlanTCP>();
            kalficomEntities context = new kalficomEntities();
            foreach (var p in context.ANAPLAN.ToList())
            {
                AnaPlanTCP anaPlan = new AnaPlanTCP();
                anaPlan.AP_CODANA = p.AP_CODANA;
                anaPlan.AP_CODPLAN = p.AP_CODPLAN;
                list.Add(anaPlan);
            }
            return list;
        }

        public List<AnalyseTCP> GetAllAnalyse()
        {
            var list = new List<AnalyseTCP>();
            kalficomEntities context = new kalficomEntities();
            foreach (var a in context.ANALYSES.ToList())
            {
                AnalyseTCP analyse = new AnalyseTCP();
                analyse.AN_CODE = a.AN_CODE;
                analyse.AN_LIBELLE = a.AN_LIBELLE;
                analyse.AN_SECTEUR = a.AN_SECTEUR;
                analyse.AN_UNITE = a.AN_UNITE;
                list.Add(analyse);
            }
            return list;
        }

        public List<AnalyseProduitTCP> GetAllAnalyseProduit()
        {
            var list = new List<AnalyseProduitTCP>();
            kalficomEntities context = new kalficomEntities();
            foreach (var a in context.ANAPRDs.ToList())
            {
                AnalyseProduitTCP analyse = new AnalyseProduitTCP();
                analyse.AS_ANA = a.AS_ANA;
                analyse.AS_ORI = a.AS_ORI;
                analyse.AS_PROD = a.AS_PROD;
                analyse.AS_UNIT = a.AS_UNIT;
                list.Add(analyse);
            }
            return list;
        }

        public List<PtsurvTCP> GetAllPtsurv()
        {
            var list = new List<PtsurvTCP>();
            kalficomEntities context = new kalficomEntities();
            foreach (var p in context.PTSURVs.ToList())
            {
                PtsurvTCP ptSurv = new PtsurvTCP();
                ptSurv.PS_CODE = p.PS_CODE;
                ptSurv.PS_LIBELLE = p.PS_LIBELLE;
                list.Add(ptSurv);
            }
            return list;
        }

        public List<PtprelTCP> GetAllPtprel()
        {
            var list = new List<PtprelTCP>();
            kalficomEntities context = new kalficomEntities();
            foreach (var p in context.PTPRELs.ToList())
            {
                PtprelTCP ptPrel = new PtprelTCP();
                ptPrel.PP_CODPREL = p.PP_CODPREL;
                ptPrel.PP_CODSURV = p.PP_CODSURV;
                ptPrel.PP_LIBELLE = p.PP_LIBELLE;
                list.Add(ptPrel);
            }
            return list;
        }

        public List<Ident01TCP> GetAllIdent01()
        {
            var list = new List<Ident01TCP>();
            kalficomEntities context = new kalficomEntities();
            foreach (var i in context.IDENT01.ToList())
            {
                Ident01TCP ident = new Ident01TCP();
                ident.ID_VALEUR = i.ID_VALEUR;
                list.Add(ident);
            }
            return list;
        }

        public List<Ident02TCP> GetAllIdent02()
        {
            var list = new List<Ident02TCP>();
            kalficomEntities context = new kalficomEntities();
            foreach (var i in context.IDENT02.ToList())
            {
                Ident02TCP ident = new Ident02TCP();
                ident.ID_VALEUR = i.ID_VALEUR;
                list.Add(ident);
            }
            return list;
        }

        public List<Ident03TCP> GetAllIdent03()
        {
            var list = new List<Ident03TCP>();
            kalficomEntities context = new kalficomEntities();
            foreach (var i in context.IDENT03.ToList())
            {
                Ident03TCP ident = new Ident03TCP();
                ident.ID_VALEUR = i.ID_VALEUR;
                list.Add(ident);
            }
            return list;
        }

        public List<Ident04TCP> GetAllIdent04()
        {
            var list = new List<Ident04TCP>();
            kalficomEntities context = new kalficomEntities();
            foreach (var i in context.IDENT04.ToList())
            {
                Ident04TCP ident = new Ident04TCP();
                ident.ID_VALEUR = i.ID_VALEUR;
                list.Add(ident);
            }
            return list;
        }

        public List<Ident05TCP> GetAllIdent05()
        {
            var list = new List<Ident05TCP>();
            kalficomEntities context = new kalficomEntities();
            foreach (var i in context.IDENT05.ToList())
            {
                Ident05TCP ident = new Ident05TCP();
                ident.ID_VALEUR = i.ID_VALEUR;
                list.Add(ident);
            }
            return list;
        }

        public List<Ident06TCP> GetAllIdent06()
        {
            var list = new List<Ident06TCP>();
            kalficomEntities context = new kalficomEntities();
            foreach (var i in context.IDENT06.ToList())
            {
                Ident06TCP ident = new Ident06TCP();
                ident.ID_VALEUR = i.ID_VALEUR;
                list.Add(ident);
            }
            return list;
        }

        public List<Ident07TCP> GetAllIdent07()
        {
            var list = new List<Ident07TCP>();
            kalficomEntities context = new kalficomEntities();
            foreach (var i in context.IDENT07.ToList())
            {
                Ident07TCP ident = new Ident07TCP();
                ident.ID_VALEUR = i.ID_VALEUR;
                list.Add(ident);
            }
            return list;
        }

        public List<Ident08TCP> GetAllIdent08()
        {
            var list = new List<Ident08TCP>();
            kalficomEntities context = new kalficomEntities();
            foreach (var i in context.IDENT08.ToList())
            {
                Ident08TCP ident = new Ident08TCP();
                ident.ID_VALEUR = i.ID_VALEUR;
                list.Add(ident);
            }
            return list;
        }

        public List<Ident09TCP> GetAllIdent09()
        {
            var list = new List<Ident09TCP>();
            kalficomEntities context = new kalficomEntities();
            foreach (var i in context.IDENT09.ToList())
            {
                Ident09TCP ident = new Ident09TCP();
                ident.ID_VALEUR = i.ID_VALEUR;
                list.Add(ident);
            }
            return list;
        }

        public List<Ident10TCP> GetAllIdent10()
        {
            var list = new List<Ident10TCP>();
            kalficomEntities context = new kalficomEntities();
            foreach (var i in context.IDENT10.ToList())
            {
                Ident10TCP ident = new Ident10TCP();
                ident.ID_VALEUR = i.ID_VALEUR;
                list.Add(ident);
            }
            return list;
        }

        public List<Ident11TCP> GetAllIdent11()
        {
            var list = new List<Ident11TCP>();
            kalficomEntities context = new kalficomEntities();
            foreach (var i in context.IDENT11.ToList())
            {
                Ident11TCP ident = new Ident11TCP();
                ident.ID_VALEUR = i.ID_VALEUR;
                list.Add(ident);
            }
            return list;
        }

        public List<Ident12TCP> GetAllIdent12()
        {
            var list = new List<Ident12TCP>();
            kalficomEntities context = new kalficomEntities();
            foreach (var i in context.IDENT12.ToList())
            {
                Ident12TCP ident = new Ident12TCP();
                ident.ID_VALEUR = i.ID_VALEUR;
                list.Add(ident);
            }
            return list;
        }
    }
}
